// index.js
// 获取应用实例
const app = getApp()
Page({
  data: {
    appAddress: {},
    i: -1
  },
    /**
   * 用户点击右上角分享***【特别注意这里，配置分享链接一定要给首页链接，要不然别人点进来又是没有返回按钮的哦】***
   */
  onShareAppMessage: function () {
    return {
      title: '泛微移动体验站',
      imageUrl: 'https://enterprise.e-cology.com.cn/cloudstore/release/42cd149d25834ac380e7cede4b55f370/resources/fwszhlogo.png',
      path: '/pages/index/index'
    }
  },

  onLoad(options) {
    this.setData({
      appAddress: app.globalData.appAddress
    })

    var value = wx.getStorageSync('ts')
    this.setData({
      i: value
    })
  },

  onShareTimeline: function () {
    return {
      title: '泛微移动体验站',
      imageUrl: 'https://enterprise.e-cology.com.cn/cloudstore/release/42cd149d25834ac380e7cede4b55f370/resources/fwszhlogo.png'
    }
  },
  /**
   * 打开客服咨询
   */
  openkfzx() {
    wx.openCustomerServiceChat({
      extInfo: {
        url: 'https://work.weixin.qq.com/kfid/kfcbb755e1fd954182d'
      },
      corpId: 'wx244a86711ee90e25',
      success(res) {
      },
      fail(res) {
      }
    })
  },

  // 打开背景由来
  openbjyl () {
    wx.navigateTo({ url: `../background/index` });
    // wx.navigateTo({ url: `../businessPhase/index` });
  },

  // 打开业务过程
  openywgc () {
    wx.navigateTo({ url: `../businessprocess/index` });
    // wx.navigateTo({ url: `../leadpath/index` });
    
  },

  leadTo(e) {
    console.log(e)
    const weburl = e.currentTarget.dataset.weburl
    const registerurl = e.currentTarget.dataset.registerurl || ""
    const wygc = e.currentTarget.dataset.wygc || ""
    wx.setStorageSync('wygc', wygc)
    let wx_weburl = weburl;
    console.log(wx_weburl)
    if (!wx_weburl.startsWith('http')) {
      wx_weburl = "https://enterprise.e-cology.com.cn/login/LoginForSSO.jsp?loginid=ywy&userpassword=1&gopage=https://enterprise.e-cology.com.cn" + encodeURIComponent(wx_weburl) ;

    }
    console.log(encodeURIComponent(wx_weburl))
    console.log(wx_weburl)
    if (registerurl) {
        let wx_registerurl = registerurl
        if (registerurl.startsWith('/')) {
            wx_registerurl = location.protocol + "//" + location.host + registerurl;
        }
        wx.navigateTo({ url: `../webview/webview?weburl=${encodeURIComponent(wx_weburl)}&registerurl=${encodeURIComponent(wx_registerurl)}` });
    } else {
        wx.navigateTo({ url: `../webview/webview?weburl=${encodeURIComponent(wx_weburl)}` });
    }
  },
  phoneClick: function(event){
    wx.makePhoneCall({
      phoneNumber: event.target.dataset.phonenumber,
      success(){},
      fail(){}
    })
  }
})